package com.chenfan.mcn.enums;

import com.alibaba.fastjson.JSONObject;
import com.chenfan.mcn.constant.NumberCst;
import com.chenfan.mcn.model.vo.StarRateCardDetailQueryVO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 刊例配置-平台信息-枚举
 *
 * @author wulg
 * @date 2021-12-28
 **/
@Getter
@AllArgsConstructor
public enum RateCardPlatformInfoEnum {

    /**
     * 定义统一接口（含基础信息、平台信息）给前端-自动渲染
     */
    PLAT_NICK_NAME("plat_nick_name", "平台昵称",true, true, false, 201),
    INDIVIDUAL_RESUME("individual_resume", "个人简介",false, false,false, 202),
    STAR_PLATFORM_ID("star_platform_id", "平台ID",false, false,false, 203),
    USER_ID("user_id", "账户ID",true, false,false, 204),
    PLAT_LINK_URL("plat_link_url", "平台链接",true, false, false,205),
    FANS_QUANTITY("fans_quantity", "粉丝数量（万）",false, false, false,206),
    INTERACTIVE_QUANTITY("interactive_quantity", "基础互动（次）",false, false, false,207),
    GRAPHIC_READING_QUANTITY("graphic_reading_quantity", "图文阅读量（万）",false, false, false,208),
    VIDEO_READING_QUANTITY("video_reading_quantity", "视频阅读量（万）",false, false, false,209),
    VIDEO_PLAY_QUANTITY("video_play_quantity", "播放量（万）",false, false, false,210),
    REMARK("remark", "备注",true, false, false,211),
    ;

    /**
     * 字段名称-跟红人平台信息表对应
     */
    private final String fieldName;

    /**
     * 字段描述
     */
    private final String fieldDesc;

    /**
     * 是否显示
     */
    private final boolean display;

    /**
     * 是否默认勾选
     */
    private final boolean autoSelect;

    /**
     * 是否是图片
     */
    private final boolean isImage;

    /**
     * 排序
     */
    private final int order;


    /**
     * 转成JSONObject对象
     * @return
     */
    public static List<JSONObject> toJsonObject() {
        List<JSONObject> list = new ArrayList<>();
        for (RateCardPlatformInfoEnum item : RateCardPlatformInfoEnum.values()) {
            if(!item.display) {
                continue;
            }
            JSONObject jsonObject = new JSONObject(4,true);
            jsonObject.put("fieldName", item.getFieldName());
            jsonObject.put("fieldDesc", item.getFieldDesc());
            jsonObject.put("autoSelect", item.autoSelect);
            jsonObject.put("order", item.getOrder());
            list.add(jsonObject);
        }
        return list;
    }

    /**
     * 根据fieldName集合获取fieldDesc集合
     * @param fieldNameList
     * @return
     */
    public static List<String> getDescList(List<String> fieldNameList) {
        if(CollectionUtils.isNotEmpty(fieldNameList)) {
            List<String > fieldDescList = new ArrayList<>(fieldNameList.size());
            for (RateCardPlatformInfoEnum item : RateCardPlatformInfoEnum.values()) {
                if (fieldNameList.contains(item.fieldName)){
                    fieldDescList.add(item.fieldDesc);
                }
            }
            return fieldDescList;
        }
        return new ArrayList<>(0);
    }

    /**
     * 获取table头信息
     * @param fieldNameList
     * @return
     */
    public static List<StarRateCardDetailQueryVO.TableHead> getTableHead(List<String> fieldNameList) {
        if(CollectionUtils.isNotEmpty(fieldNameList)) {
            List<StarRateCardDetailQueryVO.TableHead> tableHeadList = new ArrayList<>(fieldNameList.size());
            for (RateCardPlatformInfoEnum item : RateCardPlatformInfoEnum.values()) {
                if (fieldNameList.contains(item.fieldName)){
                    tableHeadList.add(new StarRateCardDetailQueryVO.TableHead(NumberCst.TWO, item.getFieldName(), item.getFieldDesc(), item.autoSelect, item.isImage, item.order));
                }
            }
            return tableHeadList;
        }
        return new ArrayList<>(0);
    }

    /**
     * 获取默认勾选的
     * @return
     */
    public static List<String> getAutoSelectList(){
        List<String> selectedList = new ArrayList<>();
        for (RateCardPlatformInfoEnum item : RateCardPlatformInfoEnum.values()) {
            if (item.autoSelect){
                selectedList.add(item.fieldDesc);
            }
        }
        return selectedList;
    }
}
